package storage;

import modeller.databasedesignmodel.DatabaseDesign;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;

/**
 * Created by:  Jason Ye
 * Date:        22/05/2012
 * Time:        14:51
 */
public class DesignSave {

    private DatabaseDesign design;
    private FileOutputStream outputStream;

    public DesignSave(DatabaseDesign design, FileOutputStream in_outputStream) {

        this.design = design;
        this.outputStream = processDatabaseDesign(design, in_outputStream);

    }

    private FileOutputStream processDatabaseDesign(DatabaseDesign dbDesign, FileOutputStream out) {

        try {

            //open the object stream
            ObjectOutputStream save = new ObjectOutputStream(out);
            // add database design to the object stream
            save.writeObject(dbDesign);

            //close object stream
            save.close();

        } catch (IOException e) {

            e.printStackTrace();
        }
        return out;
    }


}
